package com.happy016.feign;


import com.happy016.configuration.FeignConfiguration;
import com.happy016.pojo.User;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

//service-user服务名称,对应项目SpringCloud-Service-User
//@FeignClient(name = "SERVICE-USER")
// 如果没有使用eureka 则这么写:
// @FeignClient(name = "SERVICE-USER",url="SERVICE-USER服务地址")
//自定义配置写法
@FeignClient(name = "SERVICE-USER",configuration= FeignConfiguration.class)
public interface UserFeignClient {


    /**
     * 这个路径对应 service-user里面的路径
     * @author Linyb
     * @since 2017/9/30 16:19
     */
    @RequestMapping(value = "/user/get/{id}",method = RequestMethod.GET)
    User findById(@PathVariable("id") Integer id);

    /**
     * get请求方式
     * 这个路径对应 service-user里面的路径
     * @author Linyb
     * @since 2017/9/30 16:19
     */
    @RequestMapping(value = "/user/get",method = RequestMethod.GET)
    User findByIdAndUsername(@RequestParam("id") Integer id,@RequestParam("username") String username);


    /**
     * get请求方式 参数太多的时候,考虑使用map传送接收
     * 这个路径对应 service-user里面的路径
     * @author Linyb
     * @since 2017/9/30 16:19
     */
    @RequestMapping(value = "/user/get/map",method = RequestMethod.GET)
    User findByIdAndUsername(@RequestParam Map<String,Object> params);


    /**
     * 以下请求方式报错,传送实体,虽然定义使用get方式,但是feign仍然非使用post方式
     */
    @RequestMapping(value = "/user/get/entity",method = RequestMethod.GET)
    User findByIdAndUsername(@RequestParam User user);


    /**
     * 实体传送,使用post方式
     * @author Linyb
     * @since 2017/10/9 11:35
     */
    @RequestMapping(value = "/user/post",method = RequestMethod.POST)
    User findByPost(@RequestParam User user);
}
